from time import strftime

##  Represents a recording. To allow serialization, the main parameter is not stored.
class Recording:

    ##  The constructor of Recording.
    #   @param[in]  main    Main wx.App derived instance.
    def __init__(self,main):
        ##  The positions of the sensors.
        self.sensorPositions = [[] for i in range(0, len(main.sensors))]
        ##  The rotations of the sensors.
        self.sensorRotations = [[] for i in range(0, len(main.sensors))]
        ##  Array with a timestamp for each frame in the recording.
        self.timeStamps = []
        ##  The list containing the bony landmarks.
        self.bonyLandmarksRecorded = main.bonyLandmarks
        ## The list containing the GH-Joints.
        self.GHJointsRecorded = main.GHJoints
        ##  The list containing the sensors.
        self.sensorsRecorded = main.sensors
        ##  The number of frames in the recording.
        self.numberOfFrames = 0
        ##  The current frame in the recording.
        self.currentFrame = 0
        ##  The string containing the filename.
        self.filename = ""

    ##  Adds the current frame with sensorPositions and rotations to the lists.
    #   Adds a timestamp to the frame, and updates the number of frames.
    #   @param[in]  main    Main wx.App derived instance.
    def AddFrame(self,main):
        for i in range(0, len(main.sensors)):
            self.sensorPositions[i].append(main.sensors[i].position)
            self.sensorRotations[i].append(main.sensors[i].rotation)
        self.timeStamps.append(strftime("%Y-%m-%d %H:%M:%S"))
        self.numberOfFrames += 1

    ##  Calculates a list with the positions and rotation of the current frame.
    #   @return[array]  The list containing the position and rotation of each sensor in the current frame.
    def GetSensorsCurrentFrame(self):
        for i in range(0, len(self.sensorsRecorded)):
            self.sensorsRecorded[i].position = self.sensorPositions[i][self.currentFrame]
            self.sensorsRecorded[i].rotation = self.sensorRotations[i][self.currentFrame]

        return self.sensorsRecorded
        
    ## Returns the timestamp corresponding to the current frame.
    #  @return[string]  A string represantation of the time corresponding to the currentFrame.
    def GetCurrentTimeStamp(self):
        return self.timeStamps[self.currentFrame]